package surfing.chatting.client;

import java.util.Map;

import javax.swing.ImageIcon;

import surfing.chatting.ui.label.LabelUser;

public class User implements Comparable<User> {
	private String id;
	private String name;
	private ImageIcon headIcon;
	private String ip="";
	private String addr="";
	private boolean isOnline;
	private LabelUser label;
	public User() {
	}
	public void setLabel(LabelUser label) {
		this.label = label;
	}

	public User(Map<String, Object> map) {
		id = map.get("id").toString();
		name = map.get("name").toString();
		Object object = map.get("head");
		byte[] b = (byte[]) object;
		if (object != null) {
			headIcon = new ImageIcon(b);
		}
		label = new LabelUser(this);

	}

	public User(String id, String name) {
		super();
		this.id = id;
		this.name = name;
		label = new LabelUser(this);
	}
	public void changeHead(Object object) {
		byte[] b = (byte[]) object;
		headIcon= new ImageIcon(b);
		label.setHeadlabel(headIcon);
	}
	public void changeHead( byte[] b) {
		headIcon= new ImageIcon(b);
		label.setHeadlabel(headIcon);
	}
	public void changeName(String name) {
		this.name = name;
		label.setNamelabel(name);
	}
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public ImageIcon getHeadIcon() {
		return headIcon;
	}

	public void setHeadIcon(ImageIcon headIcon) {
		this.headIcon = headIcon;
	}

	public boolean isOnline() {
		return isOnline;
	}

	public void setOnline(boolean isOnline) {
		label.setOnlineStatus(isOnline);
		this.isOnline = isOnline;
	}

	public LabelUser getLabel() {
		return label;
	}
	public void setAddr(String addr) {
		this.addr = addr;
	}
	public String getAddr() {
		return addr;
	}
	public void setIp(String ip) {
		this.ip = ip;
	}
	public String getIp() {
		return ip;
	}
	@Override
	public int compareTo(User o) {
		return this.id.compareTo(o.getId());
	}

}
